<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">岗位名称</label>
        <div class="layui-input-block">
            <input type="text" name="jobName" lay-verify="required" lay-reqtext="岗位名称不能为空" placeholder="请填写岗位名称" value="" class="layui-input">
            <input type="text" name="status" value="招聘中" hidden>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">关键字</label>
        <div class="layui-input-block">
            <div id="keywordId"></div>
            <input type="text" name="keyword" value="" hidden>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">招聘人数</label>
        <div class="layui-input-block">
            <input type="text" name="recruits" placeholder="请填写招聘人数" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">薪资范围</label>
        <div class="layui-input-block">
            <select name="salary" lay-filter="salary">
                <option value="面议">面议</option>
                <option value="1k以下">1k以下</option>
                <option value="1k-3k">1k-3k</option>
                <option value="3k-6k">3k-6k</option>
                <option value="6k-10k">6k-10k</option>
                <option value="10k-15k">10k-15k</option>
                <option value="15k-20k">15k-20k</option>
                <option value="20k以上">20k以上</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">工作经验</label>
        <div class="layui-input-block">
            <select name="experiece" lay-filter="experiece">
                <option value="经验不限">经验不限</option>
                <option value="1-3年">1-3年</option>
                <option value="3-5年">3-5年</option>
                <option value="5-10年">5-10年</option>
                <option value="10年以上">10年以上</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">学历要求</label>
        <div class="layui-input-block">
            <select name="degree" lay-filter="degree">
                <option value="学历不限">学历不限</option>
                <option value="初中及以下">初中及以下</option>
                <option value="中专/中技">中专/中技</option>
                <option value="高中">高中</option>
                <option value="大专">大专</option>
                <option value="本科">本科</option>
                <option value="硕士">硕士</option>
                <option value="博士">博士</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">工作类型</label>
        <div class="layui-input-block">
            <select name="type" lay-filter="type">
                <option value="全职">全职</option>
                <option value="兼职">兼职</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">工作要求</label>
        <div class="layui-input-block">
            <select name="requirements" lay-filter="requirements">
                <option value="远程">远程</option>
                <option value="坐班">坐班</option>
                <option value="外勤">外勤</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">公司名称</label>
        <div class="layui-input-block">
            <input type="text" name="company" placeholder="请填写公司名称" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" id="area-picker">
        <div class="layui-form-label">办公区域</div>
        <div class="layui-input-inline" style="width: 200px;">
            <select name="province" class="province-selector" data-value="" lay-filter="province-1">
                <option value="" >请选择省</option>
            </select>
        </div>
        <div class="layui-input-inline" style="width: 200px;">
            <select name="city" class="city-selector" data-value="" lay-filter="city-1">
                <option value="" >请选择市</option>
            </select>
        </div>
        <input type="text" name="area" value="" hidden>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">详细地址</label>
        <div class="layui-input-block">
            <textarea name="address" class="layui-textarea" placeholder="请填写详细地址"></textarea>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">岗位联系人</label>
        <div class="layui-input-block">
            <input type="text" name="leader" placeholder="请填写岗位联系人姓名" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">岗位联系人性别</label>
        <div class="layui-input-block">
            <select name="avatar" lay-filter="avatar">
                <option value="男">男</option>
                <option value="女">女</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">岗位联系人职位</label>
        <div class="layui-input-block">
            <input type="text" name="posts" placeholder="请填写岗位联系人职位" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">联系方式</label>
        <div class="layui-input-block">
            <input type="tel" name="phone" lay-verify="required" placeholder="请填写联系方式" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">岗位详情</label>
        <div class="layui-input-block">
            <div id="editor" style="margin: 50px 0 50px 0"></div>
            <input type="text" name="details" value="" hidden>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认发布</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="../../lib/common/common.js" charset="utf-8"></script>
<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="../../js/lay-module/xm-select-master/dist/xm-select.js" charset="utf-8"></script>
<script>

    layui.use(['layer', 'form', 'layarea'], function () {
        var form = layui.form,
            layer = layui.layer,
            layarea = layui.layarea,
            $ = layui.$;

        layarea.render({
            elem: '#area-picker',
            data: {},
            change: function (res) {
                //选择结果
                let area = res.province + "-" + res.city;
                $('input[name="area"]').val(area);
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert("确定提交吗？", {
                title: '提示'
            }, function () {
                let myMsg = layer.msg("正在提交...",{
                    icon:16,
                    time:-1
                })
                $.ajax({
                    type:"post",
                    url:'/job/save',
                    data:JSON.stringify(data.field),
                    dataType:'json',
                    contentType: 'application/json; charset=UTF-8',
                    success:function(req){
                        layer.msg("已添加");
                        layer.close(index);
                        // 关闭弹出层
                        setTimeout(function () {
                            layer.close(myMsg);//手动关闭
                            let iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        }, 1500);
                    },
                    error:function(e){
                        layer.msg("添加失败");
                        layer.close(myMsg);//手动关闭
                    }
                })

            });

            return false;
        });

    });

    let xm_select = xmSelect.render({
        el: '#keywordId',
        language: 'zn',
        direction: 'down',
        data: [],
        on: function(data){
            let keyword = ''
            if(isNotNull(data.arr) && data.arr.length>0){
                for (const i in data.arr) {
                    if(keyword == ''){
                        keyword = data.arr[i].value
                    }else{
                        keyword += "," + data.arr[i].value
                    }
                }
            }
            $('input[name="keyword"]').val(keyword);
        },
        filterable: true,
        create: function(val, arr){
            //返回一个创建成功的对象, val是搜索的数据, arr是搜索后的当前页面数据
            return {
                name: val,
                value: val
            }
        }
    })

    //富文本编辑器
    layui.use(['layer','wangEditor'], function () {
        var $ = layui.jquery,
            layer = layui.layer,
            wangEditor = layui.wangEditor;

        var editor = new wangEditor('#editor');
        editor.customConfig.uploadImgServer = "../api/upload.json";
        editor.customConfig.uploadFileName = 'image';
        editor.customConfig.pasteFilterStyle = false;
        editor.customConfig.uploadImgMaxLength = 5;
        editor.customConfig.uploadImgHooks = {
            // 上传超时
            timeout: function (xhr, editor) {
                layer.msg('上传超时！')
            },
            // 如果服务器端返回的不是 {errno:0, data: [...]} 这种格式，可使用该配置
            customInsert: function (insertImg, result, editor) {
                console.log(result);
                if (result.code == 1) {
                    var url = result.data.url;
                    url.forEach(function (e) {
                        insertImg(e);
                    })
                } else {
                    layer.msg(result.msg);
                }
            }
        };
        editor.customConfig.customAlert = function (info) {
            layer.msg(info);
        };
        editor.customConfig.onchange = function (html) {
            $('input[name="details"]').val(html);
        };
        editor.create();
    });

</script>
</body>
</html>